home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / delftips / ti2857.asc < prev    next >
Encoding:
Text File  |  1996-09-15  |  1.4 KB  |  61 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2857
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  August 22, 1995                          PAGE  :  1/1
  11.  
  12.     TITLE  :  How to check to see if a drive is ready.
  13.  
  14.  
  15.  
  16.  
  17. Q:  How can I check to see if there is a disk in the "A" drive
  18.     without an error message box telling you that it is not ready?
  19.  
  20. A:  The following function accepts a drive letter as a parameter,
  21.     and it will return a boolean value that indicates whether
  22.     or not there is a disk in the drive.
  23.  
  24. function DiskInDrive(Drive: Char): Boolean;
  25. var
  26.   ErrorMode: word;
  27. begin
  28.   { make it upper case }
  29.   if Drive in ['a'..'z'] then Dec(Drive, $20);
  30.   { make sure it's a letter }
  31.   if not (Drive in ['A'..'Z']) then
  32.     raise EConvertError.Create('Not a valid drive ID');
  33.   { turn off critical errors }
  34.   ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  35.   try
  36.     { drive 1 = a, 2 = b, 3 = c, etc. }
  37.     if DiskSize(Ord(Drive) - $40) = -1 then
  38.       Result := False
  39.     else
  40.       Result := True;
  41.   finally
  42.     { restore old error mode }
  43.     SetErrorMode(ErrorMode);
  44.   end;
  45. end;
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. DISCLAIMER: You have the right to use this technical information
  58. subject to the terms of the No-Nonsense License Statement that
  59. you received with the Borland product to which this information
  60. pertains.
  61.